import { h, resolveComponent } from 'vue'
import { Plus, Delete, Edit, CopyDocument, Download, Open } from '@element-plus/icons-vue'
import { cloneDeep, get, isArray, isObject, isString } from "lodash-es"

export const operaOptionsMapper = {
  add: {
    title: '新增',
    type: 'primary',
    trigger: 'add',
    icon: Plus
  },
  eidt: {
    title: '修改',
    trigger: 'edit',
    icon: Edit
  },
  delete: {
    title: '删除',
    trigger: 'delete',
    icon: Delete
  },
  fill: {
    title: '填充',
    trigger: 'fill',
    icon: Download
  },
  copy: {
    title: '复制',
    trigger: 'copy',
    icon: CopyDocument
  },
  drag: {
    title: '拖动',
    trigger: 'drag',
    icon: Open
  },
} as Record<YTableOperaType, YTableOperaOption>


export function getOperaOptions(operas_: YTableOperas) {
  const operas = cloneDeep(operas_)
  const options: YTableOperaOption[] = []

  try {
    const getDefaultOptions = (k) => {
      return get(operaOptionsMapper, k, {})
    }

    if (operas.toString() === '[object Object]') {
      Object.keys(operas).forEach(k => {
        const opera = operas[k] as YTableOperaOption
        options.push(Object.assign(opera, getDefaultOptions(k)))
      })
    }

    if (isArray(operas)) {
      for (let opera of operas) {
        if (isString(opera)) {
          options.push(getDefaultOptions(opera))
        } else {
          Object.assign(opera, getDefaultOptions(opera.title))
          options.push(opera)
        }

      }
    }
  } catch (err) {
    console.error(err)
  }
  return options;
}